<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<?php $this->load->view('head'); ?>
	<script type="text/javascript">
		var selectedUser = false;
		jQuery(document).ready(function() {
			jQuery( "#client" ).autocomplete({
				source: function(request, response) {
					jQuery.ajax({ url: "<?php echo site_url('ri/searchuser'); ?>",
						data: { term: jQuery("#client").val() },
						dataType: "json",
						type: "POST",
						success: function(data){
							response(data);
						}
					});
				},
				minLength: 2,
				select: function( event, ui ) {
					if (ui.item) {
						jQuery("#clientid").val(ui.item.id);
						
						selectedUser = true;
					}
				}
			});
		});
	</script>
</head>

<body>
	<?php $this->load->view('header_admin.php'); ?>
	
	<!-- Content Area -->
	<div class="wrapper-world content">
		<h1>New Recurring Invoice</h1>
		
		<?php if ($jobId > 0): ?>
		<div class="wrapper">
			<div class="whitebox-top"><div class="whitebox-bot"><div class="whitebox">
				<ul>
					<li><span>Client</span> <span><?php echo anchor('viewuser/'.$jobOrder->owner_id, $jobUser->name); ?></span></li>
					<li><span>Client ID</span> <span><?php echo $jobUser->id; ?></span></li>
					<li><span>Company</span> <span><?php echo $jobUser->company; ?></span></li>
					<li><span>e-mail</span> <span><?php echo $jobUser->username; ?></span></li>
					<li><span>Telephone</span> <span><?php echo $jobUser->phone; ?></span></li>
					<li><span>Expected Start Date:</span> <span><?php $d = explode(" ", $jobRoutes[0]->start_date); echo $d[0]; ?></span></li>
					<li><span>Information Supplied:</span> <span><?php echo htmlspecialchars($jobOrder->moreinfo); ?></span></li>
					<span class="clr"></span>
				</ul>
				
				<div class="clr"></div>
			</div></div></div>
		</div>
		<?php endif; ?>
		
		<div class="wrapper">
			<?php echo form_open('ri/add'.(($jobId > 0) ? '/'.$jobId : ''), array('class' => 'standard-form', 'id' => 'addInvoice')); ?>
				<div class="one">
					<label for="client">Client Name or Client ID</label>
					<div class="type-text"><input type="text" name="client" id="client"<?php if ($jobId > 0): ?> value="<?php echo $jobUser->name; ?>"<?php endif; ?> /><input type="hidden" name="clientid" id="clientid" /></div>
					<div class="clr"></div>
				</div>
				<div class="one">
					<label for="period">Period (Months)</label>
					<div class="type-text"><input type="text" name="period" id="period" /></div>
					<div class="clr"></div>
				</div>
				<div class="one">
					<label for="startdate">Start Date</label>
					<div class="type-text"><input type="text" id="startdate" name="startdate" /></div>
					<div class="clr"></div>
				</div>
				<div class="one">
					<label for="startdate">Remarks</label>
					<div class="type-textarea"><textarea id="remarks" name="remarks"></textarea></div>
					<div class="clr"></div>
				</div>
				<input type="hidden" name="routes" value="" />
				<input type="hidden" name="addInvoice" value="true" />
			</form>
		</div>
		
		<h1>Routes <span class="quantity" id="routesCount">0</span> <span class="quantity link"><a href="javascript:addRoute();">+ New</a></span></h1>
		
		<div class="wrapper" id="routesContainer">
			
		</div>
		
		<script type="text/javascript" src="<?php echo site_url(); ?>assets/js/routes.js"></script>
		<script type="text/javascript">
			jQuery( "input#startdate" ).datepicker({dateFormat: "yy-mm-dd" });

			addRoute();
		</script>
		
		<div class="wrapper">
			<div class="action-buttons">
				<a class="more" href="javascript:submitInvoicesForm();"><span>Create Recurring Invoice</span></a>
			</div>
		</div>
	</div>	
				
		<!--          -----------------------------------------------------------------------------          -->
	
	
		
	<div class="wrapper-world footer-top">
		<div class="wrapper"></div>	
	</div>
	
	<?php $this->load->view('footer'); ?>
</body>
</html>
